<html>
	<head>
		<title>My first web page</title>

		<script>	
		function clickCounterLocal()
		{
		if(typeof(Storage)!=="undefined")
		  {
		  if (localStorage.clickcountlocal)
			{
			localStorage.clickcountlocal=Number(localStorage.clickcountlocal)+1;
			}  else    {
			localStorage.clickcountlocal=1;
			}
		  document.getElementById("result_local").innerHTML="You have clicked the button " + localStorage.clickcountlocal + " time(s).";
		  }else{
		  document.getElementById("result_local").innerHTML="Sorry, your browser does not support web storage...";
		  }
		}
		
		function clickCounterSession()
		{
		if(typeof(Storage)!=="undefined")
		  {
		  if (sessionStorage.clickcount)
			{
			sessionStorage.clickcount=Number(sessionStorage.clickcount)+1;
			}  else    {
			sessionStorage.clickcount=1;
			}
		  document.getElementById("result_session").innerHTML="You have clicked the button " + sessionStorage.clickcount + " time(s).";
		  }else{
		  document.getElementById("result_session").innerHTML="Sorry, your browser does not support web storage...";
		  }
		}
		
		function onstorage() 
		{                                                                  
            		alert([evt.key, evt.oldValue, evt.newValue].join('\n'));                                 
    		}  

		function onInit()
		{ 		
			window.addEventListener('storage', onstorage, false);
		}
		</script>
	</head>

	<body onload="onInit()">
		<br/>
		<div id="result_local"></div>
		<p><button onclick="clickCounterLocal()" type="button">Click me local!</button></p>
		<div id="result_session"></div>
		<p><button onclick="clickCounterSession()" type="button">Click me session!</button></p>
	</body>
</html>

